/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.catosist.run.business.gestorDocumentosPersona;

import com.catosist.run.dataaccess.domain.DocpersDao;
import com.catosist.run.dataaccess.model.DocpersIdVO;
import com.catosist.run.dataaccess.model.DocpersVO;
import com.catosist.run.dataaccess.model.PersonaVO;
import com.catosist.run.services.DocpersDTO;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/**
 *
 * @author Bicho
 */
public class GestorDocumentosPersonaImpl implements GestorDocumentosPersona {

    public List<DocpersDTO> getAll() {
        List<DocpersVO> docpersVOs = docpersDao.getAll();
        List<DocpersDTO> documentosPersonaDTOs = new LinkedList<DocpersDTO>();
        for (Iterator<DocpersVO> it = docpersVOs.iterator(); it.hasNext();) {
            DocpersVO docpersVO = it.next();
            DocpersDTO docpersDTO = new DocpersDTO();
            docpersDTO.setAgente(docpersVO.getAgente());
            docpersDTO.setFfin(docpersVO.getFfin());
            docpersDTO.setFinicio(docpersVO.getFinicio());
            docpersDTO.setNombre(docpersVO.getNombre());
            docpersDTO.setNumero(docpersVO.getNumero());
            docpersDTO.setPersonaId(docpersVO.getPersona().getId());

            documentosPersonaDTOs.add(docpersDTO);
        }
        return documentosPersonaDTOs;
    }

    public DocpersDTO getByIndex(int indice) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public DocpersDTO getById(int voId) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public int getIdAtIndex(int indice) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public int getIndexOf(int voId) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void saveOrUpdate(DocpersDTO o) {
        DocpersVO docpersVO = new DocpersVO();

        DocpersIdVO docpersIdVO = new DocpersIdVO(o.getId(), o.getPersonaId());
        docpersVO.setId(docpersIdVO);

        docpersVO.setNombre(o.getNombre());
        docpersVO.setNumero(o.getNumero());
        docpersVO.setAgente(o.getAgente());
        docpersVO.setFfin(o.getFfin());
        docpersVO.setFinicio(o.getFinicio());

        docpersDao.saveOrUpdate(docpersVO);
    }

    public void deleteById(int i) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void deleteByIndex(int index) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void updateListVo() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void setDocpersDao(DocpersDao docpersDao) {
        this.docpersDao = docpersDao;
    }

    public List<DocpersDTO> getByPersonaId(int personaId) {
        List<DocpersVO> docpersVOs = docpersDao.getByPersonaId(personaId);
        List<DocpersDTO> documentosPersonaDTOs = new LinkedList<DocpersDTO>();
        for (Iterator<DocpersVO> it = docpersVOs.iterator(); it.hasNext();) {
            DocpersVO docpersVO = it.next();

            DocpersDTO docpersDTO = new DocpersDTO();
            docpersDTO.setId(docpersVO.getId().getId());
            docpersDTO.setAgente(docpersVO.getAgente());
            docpersDTO.setFfin(docpersVO.getFfin());
            docpersDTO.setFinicio(docpersVO.getFinicio());
            docpersDTO.setNombre(docpersVO.getNombre());
            docpersDTO.setNumero(docpersVO.getNumero());
            docpersDTO.setPersonaId(docpersVO.getPersona().getId());

            documentosPersonaDTOs.add(docpersDTO);
        }
        return documentosPersonaDTOs;
    }

    public void deleteById(int i, int personaId) {
        DocpersVO docpersVO = new DocpersVO();
        docpersVO.setId(new DocpersIdVO(i, personaId));
        docpersDao.delete(docpersVO);
    }
    private DocpersDao docpersDao;

    public DocpersDTO getById(int id, int personaId) {
        DocpersVO docpersVO = docpersDao.get(new DocpersIdVO(id, personaId));
        DocpersDTO docpersDTO = new DocpersDTO();
        docpersDTO.setId(docpersVO.getId().getId());
        docpersDTO.setPersonaId(docpersVO.getId().getPersonaId());
        docpersDTO.setNombre(docpersVO.getNombre());
        docpersDTO.setNumero(docpersVO.getNumero());
        docpersDTO.setAgente(docpersVO.getAgente());
        docpersDTO.setFfin(docpersVO.getFfin());
        docpersDTO.setFinicio(docpersVO.getFinicio());

        return docpersDTO;
    }
}
